package com.qzsoft.zhjd.laboratory.modules.errorRecord.service.impl;

import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.Map;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qzsoft.zhjd.common.components.BaseServiceComponent;

import com.qzsoft.zhjd.laboratory.modules.errorRecord.mapper.ErrorRecordMapper;
import com.qzsoft.zhjd.laboratory.modules.errorRecord.entity.ErrorRecordEntity;
import com.qzsoft.zhjd.laboratory.modules.errorRecord.service.ErrorRecordService;


@Service("errorRecordService")
public class ErrorRecordServiceImpl extends ServiceImpl<ErrorRecordMapper, ErrorRecordEntity> implements ErrorRecordService {

    @Autowired
    private ErrorRecordMapper errorRecordMapper;

    @Autowired
    private BaseServiceComponent baseServiceComponent;

    /**
     * 列表
     */
    @Override
    public IPage<JSONObject> queryPage(Map<String, Object> params) {
        IPage<ErrorRecordEntity> page = baseServiceComponent.getPage(params, ErrorRecordEntity.class);
        return errorRecordMapper.queryPage(page,params);
    }

    /**
     * 信息
     * @return ErrorRecordEntity
     */
    @Override
    public ErrorRecordEntity getInfo(String id){
        return getById(id);
    }

    /**
     * 保存
     */
    @Override
    public void saveData(ErrorRecordEntity errorRecord){
        save(errorRecord);
    }

    /**
     * 修改
     */
    @Override
    public void updateData(ErrorRecordEntity errorRecord){
        updateById(errorRecord);
    }

    /**
     * 删除单条数据
     * @param id
     */
    @Override
    public void deleteOneData(String id){
        removeById(id);
    }

    /**
     * 删除
     */
    @Override
    public void deleteData(List<String> ids){
        removeByIds(ids);
    }

    /**
     * 保存
     */
    @Override
    public void saveErrorData(String type,String deviceId,String data){
        Date date = new Date();
        ErrorRecordEntity errorRecord = new ErrorRecordEntity();
        errorRecord.setType(type);
        errorRecord.setDeviceId(deviceId);
        errorRecord.setOriginalData(data);
        errorRecord.setCreateTime(date);
        save(errorRecord);
    }
}
